/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
*/
var search = function(nums, target) {
  let low = 0, high = nums.length - 1;
  while(low <= high) {
    let mid = Math.floor((low + high) / 2);
    if(nums[mid] < target) {
      low = mid + 1;
    } else if(nums[mid] > target) {
      high = mid - 1;
    } else {
      return mid;
    }
  }
  return -1;
};
let nums = [-1,0,3,5,9,12], target = 9;
console.log(search(nums, target));
nums = [-1,0,3,5,9,12], target = 2;
console.log(search(nums, target));
